//
// Created by chizuru on 2025/9/25.
//

#pragma once
#include "IDeviceIO.h"
#include "IConfigurable.h"
#include "IConnectable.h"
#include <iostream>

class SerialPortAdapter : public IDeviceIO , public IConfigurable, public IConnectable{
public:
    SerialPortAdapter(std::string portname);

    int configure(std::any baud, std::any dataBits, std::any parity, std::any stopBits,
                  std::any flowctrl) override;

    int write(const char *data, size_t size) override;

    int read(char *buf, size_t maxSize) override;

    int flushReadAndWrite() override;

    OperationResult connect() override;

    OperationResult close() override;

    bool isConnected() const override;

private:
    std::string portname;
    struct sp_port *port = nullptr;
};
